package test.administrator.example.com.mvptest1.list.demo;

import android.content.Context;

import test.administrator.example.com.mvptest1.framework.lce.MvpLceView;
import test.administrator.example.com.mvptest1.list.base.BasePresenter;
import test.administrator.example.com.mvptest1.list.demo.bean.PostModel;
import test.administrator.example.com.mvptest1.utils.HttpUtils;

/**
 * 作者: Dream on 16/9/24 21:28
 * QQ:510278658
 * E-mail:510278658@qq.com
 */
public class MyListPresenter extends BasePresenter<MvpLceView<PostModel>> {

	private MyListModel essenceModel;

	public MyListPresenter(Context context) {
		super(context);
		this.essenceModel = new MyListModel(context);
	}

	public void getEssenceList(int type, boolean pullToRefresh) {
		//1、显示Loading页面
		//显示LoadingView
		getView().showLoading(pullToRefresh);
		//2、发起请求的时候
		essenceModel.getEssenceList(0, type, new HttpUtils.OnLceHttpResultListener() {
			//3、更新UI->有两种情况
			@Override
			public void onCompleted() {
			}

			@Override
			public void onError(Throwable e, boolean isPullToRefresh) {
				//第一种情况：发送错误->请求失败
				//显示ErrorView
				getView().showError(e, false);
			}

			@Override
			public void onResult(Object result) {
				//第二种情况：正确->请求成功
				if (result == null) {
					//4、绑定数据->更新UI
					getView().bindData(null);
				} else {
					getView().bindData((PostModel) result);
				}
				//5、显示UI->显示ContentView
				getView().showContent();
			}
		});
	}

}
